//
//  ShellCoinDetailView.m
//  ShellWallert
//
//  Created by lvzhao on 2020/5/10.
//  Copyright © 2020 VV. All rights reserved.
//

#import "ShellCoinDetailView.h"
#import "ShellCoinDetailViewModel.h"
#import "ShellCoinDetailHeadView.h"

@interface ShellCoinDetailView()
@property (nonatomic,strong) ShellCoinDetailViewModel *viewModel;

@end

@implementation ShellCoinDetailView

- (instancetype)initViewModel:(LZBaseViewModel *)viewModel
{
    self = [super init];
    if (self) {
        
        self.viewModel = (ShellCoinDetailViewModel *)viewModel;
        [self setupView];
    }
    return self;
}


#pragma mark - setupView
#pragma mark - setupView
- (void)setupView{
    UIScrollView *scrollView = [[UIScrollView alloc] init];
    scrollView.showsVerticalScrollIndicator = NO;
    [self addSubview:scrollView];
    [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.right.bottom.mas_equalTo(0);
    }];
    
    //内容
    UIView *contentView = [[UIView alloc] init];
    [scrollView addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.and.right.equalTo(scrollView).with.insets(UIEdgeInsetsZero);
        make.width.equalTo(scrollView);
    }];
    
    ShellCoinDetailHeadView *headView = [[ShellCoinDetailHeadView alloc] initViewModel:self.viewModel];
    [contentView addSubview:headView];
    [headView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
        make.height.mas_equalTo(310);
    }];
    
    
    ///!!!:规则说明
    UILabel *ruleLab = [UILabel lz_labelWithText:LZLocalizedString(@"规则说明") fontSize:k_textFont(14) color:UIColorHex(0xFFFFFF)];
    CGFloat ruleLabHeight = [ruleLab.text lz_textHeightWithFontSize:ruleLab.font withMaxWidth:K_SCREENWIDTH - 30];
    [self addSubview:ruleLab];
    [ruleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(headView.mas_bottom).mas_offset(15);
        make.width.mas_equalTo(K_SCREENWIDTH - 30);
        make.height.mas_equalTo(ruleLabHeight);
    }];

    
    UILabel *ruleDescriptionLab = [UILabel lz_labelWithText:LZLocalizedString(@"规则说明详情") fontSize:k_textFont(12) color:UIColorHex(0x627D92)];
    CGFloat ruleDescriptionHeight = [ruleDescriptionLab.text lz_textHeightWithFontSize:ruleDescriptionLab.font withMaxWidth:K_SCREENWIDTH - 40];
    [self addSubview:ruleDescriptionLab];
    [ruleDescriptionLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(ruleLab.mas_bottom).mas_offset(10);
        make.width.mas_equalTo(K_SCREENWIDTH - 40);
        make.height.mas_equalTo(ruleDescriptionHeight);
    }];
    
    
    
    
    ///!!!:节点
    UIView *nodeView = [[UIView alloc] init];
    nodeView.backgroundColor = UIColorHex(0x14385E);
    [self addSubview:nodeView];
    [nodeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(ruleDescriptionLab.mas_bottom).mas_offset(10);
        make.width.mas_equalTo(K_SCREENWIDTH - 40);
        make.height.mas_equalTo(30);
    }];
    
    
    UILabel *nodeLevelLab = [UILabel lz_labelWithText:LZLocalizedString(@"节点等级") fontSize:k_textFont(12) color:UIColor.whiteColor];
    [nodeView addSubview:nodeLevelLab];
    [nodeLevelLab lz_centerAlignment];
    [nodeLevelLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.centerY.mas_equalTo(nodeView.mas_centerY);
        make.width.mas_equalTo((K_SCREENWIDTH - 40) / 2.0);
        make.height.mas_equalTo(30);
    }];
    
    
    UILabel *limitLab = [UILabel lz_labelWithText:LZLocalizedString(@"额度(SHELL-COIN)") fontSize:k_textFont(12) color:UIColor.whiteColor];
    [nodeView addSubview:limitLab];
    [limitLab lz_centerAlignment];
    [limitLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(0);
        make.centerY.mas_equalTo(nodeView.mas_centerY);
        make.width.mas_equalTo((K_SCREENWIDTH - 40) / 2.0);
        make.height.mas_equalTo(30);
    }];

    ///数据
    NSArray *nodeDetaiDatas = @[@"BLV1",@"1000",
                                @"BLV2",@"3000",
                                @"BLV3",@"5000",
                                @"BLV4",@"8000",
                                @"SLV1-SLV5",@"10000"];
    
    UIView *nodeDetailView = [[UIView alloc] init];
    nodeDetailView.backgroundColor = UIColorHex(0x08233F);
    [self addSubview:nodeDetailView];
    [nodeDetailView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(nodeView.mas_bottom).mas_offset(5);
        make.width.mas_equalTo(K_SCREENWIDTH - 40);
        make.height.mas_equalTo((nodeDetaiDatas.count/2) * 17 + 32 + (nodeDetaiDatas.count/2 - 1) * 6);
    }];
    

    //每个Item宽高
    CGFloat H = 17;
    CGFloat W = (K_SCREENWIDTH - 40 - 10)/2.0;
    //每行列数
    NSInteger rank = 2;
    //每列间距
    CGFloat rankMargin = 10;
    //每行间距
    CGFloat rowMargin = 6;
    //Item索引 ->根据需求改变索引
    NSUInteger index = nodeDetaiDatas.count;
    
    CGFloat top = 16;
    for (int i = 0 ; i < index; i++) {
        UILabel *detailLab = [UILabel lz_labelWithText:nodeDetaiDatas[i] fontSize:k_textFont(12) color:UIColorHex(0x627D92)];

        [detailLab lz_centerAlignment];
        //Item Y轴
        NSUInteger Y = (i / rank) * (H +rowMargin);
        //Item X轴
        CGFloat X = (i % rank) * (W + rankMargin);
        
        detailLab.frame = CGRectMake(X, Y + top, W, H);
        [nodeDetailView addSubview:detailLab];
    }
       
    
    
    
//
//    UILabel *messageLabel = [UILabel lz_labelWithText:LZLocalizedString(@"") fontSize:k_textFont(13) color:UIColorHex(0x678DA8)];
//    CGFloat messageHeight = [messageLabel.text lz_textHeightWithFontSize:messageLabel.font withMaxWidth:K_SCREENWIDTH - 30];
//    [self addSubview:messageLabel];
//    [messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(15);
//        make.top.mas_equalTo(titleLab.mas_bottom).mas_offset(10);
//        make.right.mas_equalTo(-15);
//        make.height.mas_equalTo(messageHeight);
//    }];
//
    
    [contentView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(nodeDetailView.mas_bottom).mas_offset(34);
    }];
    
//    @weakify(self);
//    [self.viewModel.reloadSubject subscribeNext:^(id  _Nullable x) {
//        @strongify(self);
//        messageLabel.text = self.viewModel.descText;
//        CGFloat messageHeight = [messageLabel.text lz_textHeightWithFontSize:messageLabel.font withMaxWidth:K_SCREENWIDTH - 30];
//
//        [messageLabel mas_updateConstraints:^(MASConstraintMaker *make) {
//               make.height.mas_equalTo(messageHeight);
//        }];
//    }];
//
//
//
//
//
//
    ///获取详情
    [self.viewModel getShellCoinDetail];
}


@end
